package 设计模式.util.prototype;



import java.io.*;
import java.util.Date;

/**
 * @功能
 * @创建时间 2020/5/3
 * 序列反序列化实现深复制
 */
public class Clintt {
    public static void main(String[] args) throws  IOException, ClassNotFoundException {
        Sheep s1 = new Sheep("11",new Date(111));
        System.out.println(s1);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(s1);
        byte[] bytes =bos.toByteArray();

        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        Sheep s2= (Sheep) ois.readObject();

        s1.setSbirthday(new Date(222));

        System.out.println(s2);
        System.out.println(s1.getSbirthday()==s2.getSbirthday());
    }
}
